using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for ShoppingCartBO
/// </summary>
public class ShoppingCartBO
{
	public ShoppingCartBO()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public DataTable GetAllShoppingCart()
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "SELECT T1.BasketId, T1.Name, T1.ShoppingDate, T2.Quantity, T3.Cost, T3.Image";
        sql += " FROM [OFSSDB].[dbo].ShoppingCart T1 JOIN [OFSSDB].[dbo].ShoppingCartDetails T2 ON T1.BasketId = T2.BasketId";
        sql += " JOIN [OFSSDB].[dbo].FastFood T3 ON T2.FoodId = T3.FoodId";
        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }

    public int ShoppingCartInsert(ShoppingCartEntity entity)
    {
        DBconnect connect = new DBconnect();
        connect.Open();
        if (connect.IsConnected == false)
            return -1;
        string[] listcol = new string[] { "BasketId", "Name", "CustomerId", "ShoppingDate", "IsDelete" };
        object[] listvalue = new object[] { entity.BasketId, entity.Name, entity.CustomerId, entity.ShoppingDate, 0};
        int i = connect.Insert("ShoppingCart", listcol, listvalue);

        string[] cols = new string[] { "BasketId", "Quantity", "FoodId", "MenuId", "IsDelete" };
        object[] values = new object[] { i , entity.Unit, entity.FoodId, 0, entity.IsDelete };
        int j = connect.Insert("ShoppingCartDetails", listcol, listvalue);

        connect.Close();
        return i;
    }
}
